package a09_贪心算法;

/**
 * <p>
 * a03_摆动序列复习0
 * </p>
 *
 * @author flyduck
 * @since 2025/1/13
 */
//1, 7, 4, 9, 2, 5
//  6 -3  5 -7  3
//比较prevDiff和currDiff一正一负就说明转折了
public class a03_摆动序列复习0 {
    public static void main(String[] args) {
        int i = wiggleMaxLength(new int[]{1, 7, 4, 9, 2, 5});
        System.out.println();
    }
    public static int wiggleMaxLength(int[] nums) {
        int result = 1;//最后一个
        int prevDiff = 0;
        int currentIdx = 0;
        while (currentIdx <= nums.length - 2) {
            int currentDiff = nums[currentIdx+1] - nums[currentIdx];
            if((prevDiff >= 0 && currentDiff < 0) || (prevDiff <= 0 && currentDiff > 0)){
                result++;
                prevDiff = currentDiff;
            }
            currentIdx++;
        }
        return result;
    }
}
